package com.example.demo.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.entity.User;
import com.example.demo.dao.UserDao;
import com.example.demo.service.UserService;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    /**
     * 通过ID查询单条数据
     *
     * @param identity_id 主键
     * @return 实例对象
     */
    @Override
    public User queryById(String identity_id) {
        return this.userDao.queryById(identity_id);
    }
    @Override
    public User queryPwd(String pwd) {
        return this.userDao.queryPwd(pwd);
    }
    @Override
    public User info(String identity_id) {
        return this.userDao.info(identity_id);
    }


    public int insertuser(User user) {
      return  this.userDao.insertUser(user);
    }
    public List<JSONObject> userlist(){
        List<User>users=userDao.userlist();
        List<JSONObject>list=new ArrayList<>();
        for(User user:users){
            list.add(user.getUserMsg());
        }
        return list;
    }



    public void authUser(int id, int role) {
        userDao.authUser(id, role);
    }



    public User getUser(String identity_id) {
        return userDao.getUser(identity_id);
    }

    public int addUser(User user){
        return userDao.insertUser(user);
    }

    public User getUserById(int id) {
        return userDao.getUserById(id);
    }

    public String updateUser(User user){

            userDao.updateUser(user);;
            return "success";



    }

    @Override
    public int insertUser(User user) {
        return userDao.insertUser(user);
    }

    @Override
    public int deleteid(int id) {
        return userDao.deleteid(id);
    }



//    public PageInfo<User> findUserList(int pageNum, int pageSize){
//        List<User> listUser= userDao.findUserList();
//
//        PageInfo<User> pageInfoList=new PageInfo<User>(listUser);
//        PageHelper.startPage(pageNum,pageSize);
//        return pageInfoList;
//    }

//       public List<User> findUserList(){
//        return userDao.findUserList();
//        } //pagehelper
}